package garin.parse;

import java.io.IOException;

public class MatchToken extends Token {
	private final String match;
	private int ignore;
	private final boolean caseSensitive;
	
	public MatchToken(final Token parent, final String match, final boolean cs) {
		super(parent);
		this.match = match;
		ignore = match.length();
		caseSensitive = cs;
	}
	
	@Override
	public boolean accept() throws IOException {
		if (source().isWhitespace()) return false;
		final boolean is = source().is(match, caseSensitive);
		return is;
	}
	
	@Override
	public Token on() throws Exception {
		if (ignore-- > 0) return self();
		return up();
	}
}
